<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>聚合收款二维码</title>
    <script src="../../resource/jquery214.js"></script>
    <script src="../../script/qrcode.js"></script>
    <script src="../../resource/jquerybarcode.js"></script>
    <script type="text/javascript" src="../../script/aes.js"></script>
    <script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
    <script type="text/javascript" src="../../script/modeecb.js"></script>
    <script src="../../script/tmd5.js"></script>
    <script type="text/javascript" src="../../script/constants.js"></script>
    <style>
    	body{
    		overflow-x:hidden;
            margin: 0;
    	}
    </style>
</head>
<body style="height:88%;">

<header id="statusBar">
		<div style="width:100%;display:table;position:fixed;z-index: 9999;height: 50px;" >
			<div style="float:left;width: 10%;height: 50px;line-height: 50px;" tapmode="presshover" onclick="closeFrm();">
			  <div style="float:right;width: 30%;height: 50px;">
			   <img style="width: 16px;margin-top: 13px;" src="../../image/jhzf/close.png" />
			   </div>
			</div>
			<div style="float:left;width: 80%;height: 50px;line-height: 50px;text-align: center;font-weight:bold;">
			     聚合收款二维码
			</div>
		</div>
	 </header>
<div style="height: 20px;"></div>
      <div id="barcode" style="clear:both;border: none;border-radius:0px;background-color: #FFF" ></div>
<div style="background: #ffffff;height: 400px;width: 90%;margin: 0 auto;border-radius: 10px;text-align: center;">
      <!-- 二维码 -->
      <div style="margin: 0 auto;font-size: 20px;padding: 30px;" id="titel">

      </div>
      <div id="cmqr" style="font-size: 20px;margin: 0 auto;text-align: center;padding-top: 10px;">
      </div>
      
      <div style="display: table;width: 100%;">
        <table style="margin: 0 auto;">
         <tr>
          <td>
           <img src="../../image/jhzf/wxpay.png" style="width:40px;"/>
          </td>
          <td style="text-align: left;font-size: 24px;">
          微 信 支 付
          </td>
         </tr>
         <tr>
          <td>
           <img src="../../image/jhzf/zfb.png" style="width:40px;"/>
          </td>
          <td style="text-align: left;font-size: 24px;">
          支付宝
          </td>
         </tr>
        </table>
      </div>
 </div> 
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
    var qrString = "";
    var orderid = "";
    var time;
    var ip = "";
    var amount = "";
    var mid = "";
	apiready = function(){
//	    if(api.systemType == "ios"){
//		   document.getElementById("statusBar").style.background = "#298cb4";
//	    }
//      $api.fixStatusBar( $api.dom('header') );
		qrString = api.pageParam.qrString;
		orderid = api.pageParam.orderid;
		ip = api.pageParam.ip;
		amount = api.pageParam.amount;
		mid = api.pageParam.mid;
        $('#cmqr').qrcode({width:200,height:200,correctLevel:0,text:utf16to8(qrString)});
			//条形码绘制
            //barcode(qrString);
        if(orderid != "" && orderid != null){
           setInterval("refrenshQr()",120000);
           time = setInterval("zfNotify('"+orderid+"')",2000);
        }
	};
	
	function refrenshQr(){
	    //console.log(amount+","+mid+","+ip);
        var callback = function(ret, err){
            //console.log(JSON.stringify(ret));
            //console.log(ret.qrString);
            if(ret){
               if(ret.success && typeof(ret.qrString) != "undefined" && ret.qrString != "undefined"){
                   $("#cmqr").html("");
                   var qrstring = ret.qrString;
                   $('#cmqr').qrcode({width:200,height:200,correctLevel:0,text:utf16to8(qrstring)});
               }else{
                   api.alert({msg: ret.msg});
               }
            }
        }
        var parameter = {"mid":mid,"phone":$api.getStorage("dl_phone"),"ip":ip,"total":amount};//$api.getStorage("dl_phone")
        console.log(JSON.stringify(parameter));
        apiAjax(JSON.stringify(parameter),url.createQr,callback);
	}
	
	function zfNotify(orderid){
         var callback = function(data, err){
            if(data){
            $("#loadingToast").hide();
	        if (data.STATE == "0001") {	
	          clearInterval(time);
	          api.openWin({
	              name: 'payResult',
	              url: './payResult.html',
	              pageParam: {
						id:data.ORDERID,
						amt:data.AMOUNT,
						zt:1
				  }
              });
	        }else{
	          clearInterval(time);
	          var msgc = data.MSG;
	          api.openWin({
	              name: 'payResult',
	              url: './payResult.html',
	              pageParam: {
						msg:msgc,
						zt:2
				  }
              });
	        }
          }
        }
        var content = {"orderid":orderid};
        apiAjax(JSON.stringify(content),url.ylPayResult,callback);
  }
	
    function closeFrm(){
        api.sendEvent({
	        name:'hideMask'
        });
        //api.closeFrame();
    }
    
    function utf16to8(str) { var out, i, len, c; out = ""; len = str.length; for(i = 0; i < len; i++) { c = str.charCodeAt(i); if ((c >= 0x0001) && (c <= 0x007F)) { out += str.charAt(i); } else if (c > 0x07FF) { out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F)); out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } else { out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } } return out; }	
//	function barcode(str){
//  $("#barcode").html('');
//  /* 绘制条形码 */
//  $("#barcode").barcode(str, "code128",{
//    width:0,
//    output:'bmp',       //渲染方式 css/bmp/svg/canvas
//    bgColor: '#ffffff', //条码背景颜色
//    color: '#000000',   //条码颜色
//    barWidth: 2,        //单条条码宽度
//    barHeight: 80,     //单体条码高度
//   // moduleSize: 1,   //条码大小
//    // posX: 10,        //条码坐标X
//    // posY: 5,         //条码坐标Y
//    addQuietZone: false  //是否添加空白区（内边距）
//  });
//
//  //  $("#barcode").css('width', '60rem');
//   $("#barcode").width(document.documentElement.clientWidth*0.9);
//
//}
</script>
</html>